import { DARK_MODE_KEY, ThemeEnum } from './enums'
import { useDarkStore } from './store'
import { logger } from '@/apps/logger'

/**初始化 Dark 模式 */
function initDarkApp() {
  logger.gradient('Init Dark App.')
  const darkMode = localStorage.getItem(DARK_MODE_KEY)
  if (darkMode) {
    logger.debug(`DARK_MODE_KEY = ${darkMode}`)
    const store = useDarkStore()
    if (darkMode === ThemeEnum.DARK) {
      store.themeMode = ThemeEnum.DARK
    } else if (darkMode === ThemeEnum.LIGHT) {
      store.themeMode = ThemeEnum.LIGHT
    } else {
      store.themeMode = ThemeEnum.LIGHT
      logger.warn(`Unexcept ${DARK_MODE_KEY} storage value: ${darkMode}`)
    }
  } else {
    logger.warn(`can not font value from localStorage for key ${DARK_MODE_KEY}`)
  }
}

export { initDarkApp }
